package com.huabo.contract.mysql.mapper;


import com.hbfk.util.PageInfo;
import com.huabo.contract.mysql.entity.TblOrganizationMySql;
import com.huabo.contract.mysql.entity.TblStaffMySql;
import org.apache.ibatis.annotations.*;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

import java.math.BigDecimal;

public interface TblStaffMySqlMapper extends BaseMapper<TblStaffMySql> {

	@Select("SELECT STAFFID,REALNAME,ORGID,USERNAME FROM TBL_STAFF WHERE STAFFID = #{staffId}")
	@Results({
		@Result(column="STAFFID",property="staffid"),
		@Result(column="REALNAME",property="realname"),
		@Result(column="ORGID",property="orgid"),
		@Result(column="USERNAME",property="username"),
	})
	TblStaffMySql selectStaff(@Param("staffId")String staffId) throws Exception;
	
	@Select("SELECT TS.STAFFID,TS.REALNAME,TS.USERNAME,TS.ADDRESS,TS.MIBLEPHONE,TS.MEMO,TS.STATUS,TS.CREATETIME,TS.JOBID,TS.OUTSIDEID,TS.OUTSIDEOPENDID,TS.EMAIL,TS.FIXEDPHONE,TR.RID,TR.RNAME,ORG.ORGID,ORG.ORGNAME FROM TBL_STAFF TS LEFT JOIN TBL_ROLE TR ON TS.ROLEID = TR.RID LEFT JOIN TBL_ORGANIZATION ORG ON TS.ORGID = ORG.ORGID WHERE TS.USERNAME = #{userName} AND TS.PASSWORD = #{password}")
	@Results({
		@Result(column="STAFFID",property="staffid"),
		@Result(column="REALNAME",property="realname"),
		@Result(column="USERNAME",property="username"),
		@Result(column="ADDRESS",property="address"),
		@Result(column="EMAIL",property="email"),
		@Result(column="MIBLEPHONE",property="miblephone"),
		@Result(column="MEMO",property="memo"),
		@Result(column="STATUS",property="status"),
		@Result(column="CREATETIME",property="createDate"),
		@Result(column="JOBID",property="jobid"),
		@Result(column="OUTSIDEID",property="outSideId"),
		@Result(column="OUTSIDEOPENDID",property="outSideOpenId"),
		@Result(column="FIXEDPHONE",property="fixedphone"),
		@Result(column="RID",property="trole.rid",id=true),
		@Result(column="RNAME",property="trole.rname"),
		@Result(column="ORGID",property="linkDetp.orgid",id=true),
		@Result(column="ORGNAME",property="linkDetp.orgname"),
	})
	TblStaffMySql selectUniqueStaffInfo(@Param("userName")String userName,@Param("password") String password) throws Exception;

	@Select("SELECT * FROM TBL_STAFF WHERE (STATUS is NULL or STATUS != 0) and ROLEID in (select RID from TBL_ROLE where rname= #{rolename} and COMPANYID= #{orgid})")
	TblStaffMySql findByRolename(String rolename, String orgid);
	@SelectProvider(type=TblStaffMapperSqlMySqlConifg.class,method="findByRolelOne")
	TblStaffMySql findByRolelOne(String rolename, String orgid);

	@SelectProvider(method = "selectListByPageInfo",type = TblStaffMapperSqlMySqlConifg.class)
    List<TblStaffMySql> selectListByPageInfo(PageInfo<TblStaffMySql> pageInfo, BigDecimal orgid, TblOrganizationMySql organization);

	@SelectProvider(method = "selectListByPageInfoCount",type = TblStaffMapperSqlMySqlConifg.class)
	Integer selectListByPageInfoCount(BigDecimal orgid, TblOrganizationMySql organization);

	@SelectProvider(method = "findAllPageBeanPid",type = TblStaffMapperSqlMySqlConifg.class)
    List<TblStaffMySql> findAllPageBeanPid(PageInfo<TblStaffMySql> pageInfo, TblOrganizationMySql attribute);
	@SelectProvider(method = "findAllCountPageBeanPid",type = TblStaffMapperSqlMySqlConifg.class)
	Integer findAllCountPageBeanPid(PageInfo<TblStaffMySql> pageInfo, TblOrganizationMySql attribute);

	@Select("SELECT * FROM TBL_STAFF WHERE STAFFID =#{staffid}")
	TblStaffMySql findByStaffid(String staffid);

	@SelectProvider(method = "selectListByPage",type = TblStaffMapperSqlMySqlConifg.class)
	PageInfo selectListByPage(PageInfo<TblStaffMySql> pageInfo, BigDecimal orgid, TblOrganizationMySql organization);

	@UpdateProvider(method = "updateTs",type = TblStaffMapperSqlMySqlConifg.class)
    void updateTs(TblStaffMySql ts);

	@InsertProvider(method = "saveTs",type = TblStaffMapperSqlMySqlConifg.class)
	void saveTs(TblStaffMySql ts);

	TblStaffMySql findByJobName(String string, String string2);
}
